import java.util.*;
public class Doctormanage {
    //tao bang bam voi kieu cu the cho <K,V> la <String,Doctor>
    HashMap<String,Doctor> doctorList;
    /*Create a new instance of DoctorManage*/
    public Doctormanage()
    {
        doctorList = new HashMap<String,Doctor>();
    }
    //chuc nang them 1 bac si
    public void add()
    {
        Scanner sc=new Scanner(System.in);
        System.out.print("Input new details of new doctor:");
        boolean codeExisted=false;//bien giup kiem tra trung ma
        String newCode="";
        //nhap ma bac si , dieu kien khong trung ma
        do {            
            System.out.print("\nDoctor code: ");
            newCode=sc.next();
            codeExisted = doctorList.containsKey(newCode);
            if(codeExisted)
                System.out.print("This code existed!");
        } while (newCode.length()==0 || codeExisted==true);
    Doctor d=new Doctor();
    System.out.print("Nhap thong tin chi tiet va bac si nay:");
    d.input();
    doctorList.put(newCode, d);//dua d vao danh sach
    }
    public void search()//chuc nang tim kiem bac si theo ma
    {
        String aCode="";
        Scanner sc =new Scanner(System.in);
        System.out.print("Nhap aCode la ma bac si can tim : ");
        aCode=sc.next();
        if(doctorList.containsKey(aCode)==false)
           System.out.print("The doctor does not exist!");
        else
        {
            Doctor d=(Doctor)doctorList.get(aCode);
            System.out.print("Information found : ");
            d.output();
        }
    }
    public void list()//chuc nang in danh sach bac si
    {
        if(doctorList.isEmpty())
                System.out.print("List of empty!");
        else
        {
            System.out.print("List of doctors");
            System.out.print("--------------------------------------");
            Set Keys = doctorList.keySet();//lay ra tap key
            Iterator it = Keys.iterator();//lay doi tuong giup duyet danh sach
            while(it.hasNext())//khi con phan tu trong danh sach
                ((Doctor)doctorList.get((String)it.next())).output();//xuat thogn tin chi tiet
        }
    }
    public static void main(String[] args) {
            Doctormanage dm = new Doctormanage();
    int select;
    Scanner sc = new Scanner(System.in);
    do {
      System.out.println("\nSelect the operation you want to perform:");
      System.out.println("1. Register Doctor");
      System.out.println("2. Display the Doctor details");
      System.out.println("3. Publish the entire list");
      System.out.println("4. Exit");
      System.out.println("-----------------------------");
      System.out.print("Select operation 1/2/3/4 : ");
      select = sc.nextInt();
      switch(select) {
        case 1:dm.add();break;
        case 2:dm.search();break;
        case 3:dm.list();break;
        case 4:break;
        default:
          System.out.print("Invalid select");
      }
    } while(select!= 4);
  }
}
